home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / FinderFlocks / Shell / events.cp < prev    next >
Text File  |  1996-06-22  |  2KB  |  91 lines

  1. #include    "Shell.h"
  2. #include    "CFlock.h"
  3.  
  4. extern Boolean                    gDoneFlag;
  5.  
  6. extern RgnHandle                gWorldRgn;
  7. extern struct GMParamBlock        gParamBlock;
  8.  
  9. // a sick hack for key control of the flock
  10. extern ControlRec            gCurrentControls;
  11. extern Boolean                gControlsChanged;
  12.  
  13. // The global flock
  14. extern CFlock    *gTheFlock;
  15.  
  16. // local prototypes
  17. void DoControlClick(ControlHandle cHndl, short cPart, Point thePt);
  18. pascal void MyScrollProc(ControlHandle cntl, short part);
  19. void DrawScrollValue(ControlHandle cntl);
  20. void DrawScrollName(ControlHandle cntl);
  21.  
  22. /*-------------------------------------------------------------------------
  23. DoEvent()            General Event Handler...
  24. -------------------------------------------------------------------------*/
  25.  
  26. void DoEvent(EventRecord *Event)
  27. {
  28.     GrafPtr        oldport;
  29.     
  30.     switch(Event->what)
  31.     {
  32.         case activateEvt:
  33.             break;
  34.                 
  35.         case updateEvt:
  36.             GetPort(&oldport);
  37.             SetPort((WindowPtr)Event->message);
  38.             BeginUpdate((WindowPtr)Event->message);
  39.             EndUpdate((WindowPtr)Event->message);
  40.             SetPort(oldport);
  41.             break;
  42.  
  43.         case mouseDown:
  44.             break;
  45.             
  46.         case keyDown:
  47.         case autoKey:
  48.             DoKey(Event);
  49.             break;
  50.         
  51.         case app4Evt:
  52.             break;
  53.         
  54.         case nullEvent:
  55.             if(!(Event->modifiers & alphaLock))
  56.             {
  57.                 OSErr    err;
  58.  
  59.                 // if the controls changed, tell flock
  60.                 if(gControlsChanged)
  61.                 {
  62.                     gTheFlock->ControlsChanged(&gCurrentControls, gWorldRgn);
  63.                     gControlsChanged = false;
  64.                 }
  65.                 
  66.                 // Step the flock
  67.                 err = gTheFlock->FlockStep(gWorldRgn);
  68.             }
  69.             break;
  70.     }
  71. }
  72.  
  73.  
  74. /*-----------------------------------------------------------------------
  75. DoKey()            Handles keypresses...
  76. ------------------------------------------------------------------------*/
  77.  
  78. void DoKey(EventRecord *eventptr)
  79. {
  80.     char    key;
  81.     
  82.     key = (char)(eventptr->message);
  83.     
  84.     FlockControlKey(key);
  85.     if(eventptr->modifiers & cmdKey)
  86.     {
  87.         gDoneFlag = true;
  88.     }
  89. }
  90.     
  91.